home *** CD-ROM | disk | FTP | other *** search
- #include <dos.h>
- #include <stdio.h>
- main()
- {
- char name[60],outname[60];
- long p,start,end;
- int r,ch;
- char *buffer;
- FILE *index,*quote;
- char *calloc();
- unsigned size;
- long end_file;
- int count;
-
- randomize();
-
- index = fopen("quote.idx","ab"); end_file = ftell(index);
- index = fopen("quote.idx","rb");
- quote = fopen("quote.dat","rb");
-
- fseek(index,(end_file - 10L),0);
- fscanf(index,"%10d",&count); /* find number of quotes available */
-
- r = random(1,count);
- p = (long) ((r - 1) * 23L); /* pick one at random */
-
- fseek(index,p,0);
- fscanf(index,"%10ld %10ld",&start,&end); /* get quotes start & end */
-
- size = (unsigned) (end - start);
- buffer = calloc(1,size);
- fseek(quote,start,0);
- fread(buffer,size-1,1,quote); /* get the text of the quote */
-
- out_str(buffer,size); /* print it to the console */
-
- free(buffer); /* clean up */
- }
-
- int get_seed()
- {
- union REGS inregs,outregs;
- inregs.x.ax = 0x2c00; /* get time function number */
- intdos(&inregs,&outregs);
- return(outregs.h.dh * 100 + outregs.h.dl);
- }
-
- int random(start,range)
- int start,range;
- {
- return((rand() % range) + start);
- }
-
- int randomize()
- {
- srand(get_seed());
- }
-
- int out_str(buf,size)
- char *buf;
- int size;
- {
- int i;
- for(i=0;i<size;i++) putchar(*(buf++));
- }
-